﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project.MVC.Model;
using Project.MVC.MsSQLDAL;
namespace Project.MVC.Service
{
    public class CategoryServices : ICategoryServices
    {
        ICategoryRepository repository = null;
        public CategoryServices()
            : this(new CategoryRepository())
        {
        }

        public CategoryServices(ICategoryRepository rep)
        {
            repository = rep;
            if (repository == null)
                throw new InvalidOperationException("Repository cann't be null");
        }
        public IQueryable<CategoryInfo> GetList2Grid()
        {
            return repository.GetList();
        }

        public List<CategoryInfo> GetList()
        {
            return repository.GetList().ToList();
        }

        public List<CategoryInfo> GetList(int start, int offset)
        {
            throw new NotImplementedException();
        }
        public CategoryInfo GetByKey(int id)
        {
            return repository.GetList().Where(c => c.Id == id).Single();
        }
        public bool Insert(CategoryInfo value)
        {
            return repository.Insert(value);
        }

        public bool Update(CategoryInfo value)
        {
            return repository.Update(value);
        }

        public bool Delete(CategoryInfo value)
        {
            return repository.Delete(value);
        }

        public void SaveChange()
        {
            repository.Commit();
        }

        public int Count()
        {
           return repository.Count();
        }
    }
}
